//
//  M_CatalogSubCell.swift
//  letuofu
//
//  Created by WH-JS on 2019/12/13.
//  Copyright © 2019 WH-JS. All rights reserved.
//

import UIKit

class M_CatalogSubCell: UICollectionViewCell {
    let width = 375//获取屏幕宽
    let titleLab = UILabel()
    let selView = UIView()
    let logoImg = UIImageView()
    var celldata : [String : Any?]? {
        didSet{
            loadData()
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        initView()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func initView(){
        self.backgroundColor = .white
        drawImage(imageView:logoImg, named: nil) { (make) in
            make.centerX.equalToSuperview()
            make.centerY.equalToSuperview().offset(-10)
            make.width.equalTo(50)
            make.height.equalTo(50)
        }
        
        drawView(view: selView) { (make) in
            make.top.equalTo(logoImg.snp.bottom).offset(10)
            make.left.right.bottom.equalToSuperview()
        }
        
        selView.drawLabel(label: titleLab, text: "", fontSize: 12, textColor: .x333333) { (make) in
            make.center.equalToSuperview()
            make.width.equalToSuperview().offset(-5)
        }
        .textAlignment = .center
    }
    
    func loadData() {
        if var urlstring = celldata?.getString("cataLogo") {
            urlstring = (IMG_HOST_URL+urlstring).addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!
            let url = URL(string: urlstring)
            logoImg.sd_setImage(with:url)
        }else{
            logoImg.image = nil
        }
        titleLab.text = celldata?.getString("cataName")
    }
}


class M_CatalogSubHead: UICollectionReusableView {
    let titleLab = UILabel()
    var title = "" {
        didSet{
            titleLab.text = title
        }
    }
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        //页面设置
        setupUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func draw(_ rect: CGRect) {
    }
    
    func setupUI() {
        self.backgroundColor = .white
        drawLabel(label: titleLab, text: title, fontSize: 14,fontWeight: .medium, textColor: .x333333) { (make) in
            make.left.equalToSuperview().offset(16)
            make.centerY.equalToSuperview()
        }
        
        //画横线
        let line = drawView { (make) in
            make.left.equalToSuperview().offset(15)
            make.right.equalToSuperview().offset(-15)
            make.bottom.equalToSuperview().offset(-1)
            make.height.equalTo(1)
        }
        line.backgroundColor = .xF2F2F2
    }
}

class M_CatalogSubCell_Lab: UICollectionViewCell {
    let width = 375//获取屏幕宽
    let titleLab = UILabel()
    let selView = UIView()
    var celldata : [String : Any?]? {
        didSet{
            loadData()
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        initView()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func initView(){
        self.backgroundColor = .white
        drawView(view: selView) { (make) in
            make.center.equalToSuperview()
            make.left.right.equalToSuperview()
            make.top.equalToSuperview().offset(10)
            make.bottom.equalToSuperview().offset(-10)
        }
        // 设置边框
        selView.layer.borderWidth = 1
        selView.layer.borderColor = UIColor.x666666.cgColor
        selView.layer.cornerRadius = 15
        
        selView.drawLabel(label: titleLab, text: "", fontSize: 12, textColor: .x666666) { (make) in
            make.center.equalToSuperview()
            make.width.equalToSuperview().offset(-5)
        }
        titleLab.textAlignment = .center
        titleLab.numberOfLines = 2
    }
    
    func loadData() {
        titleLab.text = celldata?.getString("cataName")
    }
}

